import { Session } from "@/utils/storage";

export const buildMenuTree = (menuItems: any, parentId = 0) => {
    return menuItems
        .filter((item: any, i: number) => item.parentId === parentId)
        .map((item: any) => ({
            ...item,
            level: parentId,
            children: buildMenuTree(menuItems, item.id)
        }));
};


export const getMenuTree = () => {
    const menus = Session.get('userInfo')?.menuList ?? []
    return buildMenuTree(menus);
}